﻿/*****************************************************************************
   Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
******************************************************************************/

namespace Tensorflow
{
    public class StringOrFunction
    {
        private object variable;

        private StringOrFunction(object val)
        {
            variable = val;
        }

        public static implicit operator StringOrFunction(string val)
        {
            return new StringOrFunction(val);
        }

        public static implicit operator StringOrFunction(Function val)
        {
            return new StringOrFunction(val);
        }

        public bool IsFunction
        {
            get
            {
                return variable is FunctionDef;
            }
        }

        public override string ToString()
        {
            if (variable == null)
                return "";

            if (!IsFunction)
            {
                return variable.ToString();
            }

            return ((FunctionDef)variable).ToString();
        }
    }

    public class _UserDeviceSpec
    {
        private StringOrFunction _device_name_or_function;
        private string display_name;
#pragma warning disable CS0169 // The field '_UserDeviceSpec.function' is never used
        private FunctionDef function;
#pragma warning restore CS0169 // The field '_UserDeviceSpec.function' is never used
#pragma warning disable CS0169 // The field '_UserDeviceSpec.raw_string' is never used
        private string raw_string;
#pragma warning restore CS0169 // The field '_UserDeviceSpec.raw_string' is never used

        public _UserDeviceSpec(StringOrFunction device_name_or_function)
        {

            _device_name_or_function = device_name_or_function;
            display_name = device_name_or_function.ToString();
        }
    }
}
